package springframework.bean;

import com.qumoyugo.springframework.beans.factory.annotation.Autowired;
import com.qumoyugo.springframework.beans.factory.annotation.Value;
import com.qumoyugo.springframework.stereotype.Component;

import java.util.Random;

/**
 * @author Cedric
 * @date 2021/11/16 11:28
 * @description 定义一个Bean组件
 */
@Component("userService")
public class UserService implements IUserService {

    @Value("${token}")
    private String token;

    @Autowired
    private UserDao userDao;

    @Override
    public void queryUserInfo() {
        try {
            Thread.sleep(new Random(1).nextInt(100));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("查询用户" + token + "信息:" + userDao.queryUserName("10001"));
    }

    @Override
    public String toString() {
        return "UserService#token = {" + token + "}";
    }
}
